<?php

//Load Master Page
require_once('../shared/layout.php');

class Index extends Layout {

    protected $intServiceId;
    protected $objService;
    protected $objServiceArray;
    protected $objProjectArray;

    protected function Form_Create() {
        parent::Form_Create();

        $this->strTitle = 'Our Services';
        
        $this->objDefaultWaitIcon->AddCssFile('../../../content/plugins/jquery-prettyPhoto/css/prettyPhoto.css');
        
        $this->objDefaultWaitIcon->AddJavascriptFile('../../../content/plugins/jquery-prettyPhoto/js/jquery.prettyPhoto.js');
        $this->objDefaultWaitIcon->AddJavascriptFile('../../../content/js/service/index.js');
        
        $this->objServiceArray =
                Service::LoadAll(
                        QQ::Clause(QQ::OrderBy(QQN::Service()->Order)));

        $this->intServiceId = QApplication::QueryString('intId');

        if ($this->intServiceId == null) {
            $this->objService = $this->objServiceArray[0];
        } else {
            $this->objService = $this->FindServiceById($this->intServiceId, $this->objServiceArray);
        }

        $this->objProjectArray = Project::QueryArray(
                        QQ::AndCondition(
                                QQ::Equal(QQN::Project()->ProjectService->ServiceId, $this->objService->Id), 
                                QQ::Equal(QQN::Project()->IsEnable, true)), 
                        QQ::Clause(QQ::OrderBy(QQN::Project()->Name)));
    }

    private function FindServiceById($intServiceId, $objServiceArray) {
        foreach ($objServiceArray as $objService) {
            if ($objService->Id == $intServiceId) { return $objService; }
        }
    }
}

Index::Run('Index', __DOCROOT__ . __SUBDIRECTORY__ . '/view/service/index.tpl.php');
?>